/*
 * Copyright (c) 2024-2025 iSOFT INFRASTRUCTURE SOFTWARE CO., LTD.
 * easyAda is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#ifndef __UAPI_CAPS_CAPABILITY_H__
#define __UAPI_CAPS_CAPABILITY_H__

#include <tools/macros.h>

#define CAP_TYPE_BITS (4)

enum capability_type {
    CAP_EMPTY = 0,
    CAP_CNODE,
    CAP_NTFN,
    CAP_EP,
    CAP_IRQ_CONTROL,
    CAP_IRQ_HANDLER,
    CAP_THREAD,
    CAP_RAM,
    CAP_ADDRSPACE,
    CAP_AUDIT,

    CAP_ARMSMC,
    CAP_MUTEX,
    CAP_COND,
    CAP_SIGNAL,
    CAP_COUNT,

    KOBJECT_AS_PUD,
    KOBJECT_AS_PMD,
    KOBJECT_AS_PT,
    KOBJECT_IPCBUFFER
};

typedef struct capability {
    unsigned long w;

    unsigned long ww;

    struct capability *next;
    struct capability *parent;
} capability_t;

static inline unsigned long cap_get_type(const capability_t *cap)
{
    return cap->ww & lowbitsmask(CAP_TYPE_BITS);
}

static inline unsigned long cap_get_long_info(const capability_t *cap)
{
    return cap->w;
}

static inline unsigned long cap_get_short_info(const capability_t *cap)
{
    return cap->ww >> CAP_TYPE_BITS;
}

static inline int cap_is_empty(const capability_t *cap)
{
    return cap_get_type(cap) == CAP_EMPTY;
}

#endif
